package zozopo.background.operator;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.DepartmentOS;
import zozopo.background.operator.operations.DepartmentTB;
import zozopo.background.operator.operations.OperatorOS;
import zozopo.background.operator.operations.OperatorTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ModifyOperatorInfoAction extends ActionSupport implements Action,SessionAware{
	
	//传入参数
	private String firstname_operator;
	private String lastname_operator;

	private String qq_operator;
	private String email_operator;
	private String password_operator;
	
	private String departments_operator;
	private String office_operator;
	private String address_operator;
	private String mobile_operator;
	private String phone_operator;
	
	private int id_department;
	
	//传出参数
	private OperatorTB operator;
	
	private Map<Object, Object> session;
	
	
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		
		
		
		session = arg0;
	}
	
	public String execute(){
		OperatorOS operatorOS = new OperatorOS();
		DepartmentOS departmentOS = new DepartmentOS(operatorOS.getConn());
		
		
		operator = operatorOS.getInfoByEmail(email_operator);
		DepartmentTB department = departmentOS.getDepartment(id_department);
		
		operator.setDepartmentid_operator(department.getId_department());
		operator.setDepartmentlevel_operator(department.getLevel_department());
		operator.setDepartmentname_operator(department.getName_department());
		
		
		
		operator.setAddress_operator(address_operator);
		operator.setOffice_operator(office_operator);
		
		operator.setFirstname_operator(firstname_operator);
		operator.setLastname_operator(lastname_operator);
		operator.setMobile_operator(mobile_operator);
		operator.setPhone_operator(phone_operator);
		operator.setQq_operator(qq_operator);
		
		
		operatorOS.update(operator);
		operatorOS.releaseConnection();
		return SUCCESS;
	}
	
	public void validate() {
		//权限处理
		//UserTB user = (UserTB) session.get("userInfo");
		
		operator = (OperatorTB)session.get("operatorInfo"); 

		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		if(!OperatorOS.operatorFlagLeve(operator, 17, 1)){
			
			addFieldError("errormessage","权限不足");
			return ; 
		}//*/
		
	
		
	}

	public OperatorTB getOperator() {
		return operator;
	}

	public void setOperator(OperatorTB operator) {
		this.operator = operator;
	}



	public String getFirstname_operator() {
		return firstname_operator;
	}

	public void setFirstname_operator(String firstname_operator) {
		this.firstname_operator = firstname_operator;
	}

	public String getLastname_operator() {
		return lastname_operator;
	}

	public void setLastname_operator(String lastname_operator) {
		this.lastname_operator = lastname_operator;
	}

	public String getQq_operator() {
		return qq_operator;
	}

	public void setQq_operator(String qq_operator) {
		this.qq_operator = qq_operator;
	}

	public String getEmail_operator() {
		return email_operator;
	}

	public void setEmail_operator(String email_operator) {
		this.email_operator = email_operator;
	}

	public String getPassword_operator() {
		return password_operator;
	}

	public void setPassword_operator(String password_operator) {
		this.password_operator = password_operator;
	}

	public String getDepartments_operator() {
		return departments_operator;
	}

	public void setDepartments_operator(String departments_operator) {
		this.departments_operator = departments_operator;
	}

	public String getOffice_operator() {
		return office_operator;
	}

	public void setOffice_operator(String office_operator) {
		this.office_operator = office_operator;
	}

	public String getAddress_operator() {
		return address_operator;
	}

	public void setAddress_operator(String address_operator) {
		this.address_operator = address_operator;
	}

	public String getMobile_operator() {
		return mobile_operator;
	}

	public void setMobile_operator(String mobile_operator) {
		this.mobile_operator = mobile_operator;
	}

	public String getPhone_operator() {
		return phone_operator;
	}

	public void setPhone_operator(String phone_operator) {
		this.phone_operator = phone_operator;
	}

	public int getId_department() {
		return id_department;
	}

	public void setId_department(int id_department) {
		this.id_department = id_department;
	}

}
